<template>
    <section class="dc-edit" v-focus>
        <XdoCard class="xdo-card" :bordered="false">

            <div class="xdo-card-body">
                <XdoForm ref="formItem" class="dc-form" :model="formItem" label-position="right" :label-width="120" :rules="ruleValidate" inline>
                    <XdoFormItem prop="tradeCode" label="经营单位编码" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.tradeCode" :disabled="showDisable" xid="d_tradeCode"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="emsNo" label="账册编号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.emsNo" :disabled="showDisable" xid="d_emsNo"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="billListNo" label="清单流水号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.billListNo" :disabled="showDisable" xid="d_billListNo"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="actlPassQty" label="实际过卡数量" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.actlPassQty" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_actlPassQty"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="classifyMark" label="归类标志" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.classifyMark" :disabled="showDisable" xid="d_classifyMark"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="codeTS" label="商品编码" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.codeTS" @on-click="getUnitByCodeTs" :icon="icon"
                                   trigger="hover" title="获取最新商品编码法一法二信息" content="获取最新商品编码法一法二信息" :disabled="isDisabled" xid="d_codeTS">
                        </XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="copGNo" label="料号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" icon="ios-search" @on-click='getCurList'  v-model="formItem.copGNo" @keyup.enter.native="getCopGNoMessage"   :disabled="showDisable" xid="d_copGNo"> </XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="curr" label="币制" xid="c_head_edit_form_item">
                        <xdo-select v-model="formItem.curr" :disabled="currDisable" :asyncOptions="pcodeList" :meta="pcode.curr_outdated" @on-change='ttt' :optionLabelRender="pcodeRender" xid="d_curr"></xdo-select>
                    </XdoFormItem>
                    <XdoFormItem prop="dataMark" label="数据标识" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.dataMark" :disabled="showDisable" xid="d_dataMark"></XdoIInput>
                    </XdoFormItem>
                  <XdoFormItem prop="qty" label="申报数量" xid="c_head_edit_form_item">
                    <xdo-input v-model.trim="formItem.qty" placeholder="" @keyup.enter.native="getQty1AndQty2" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_qty"></xdo-input>
                  </XdoFormItem>
                    <XdoFormItem prop="decPrice" label="申报单价" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.decPrice" placeholder="" @keyup.enter.native="countPrice" decimal int-length="14" precision="5" :disabled="showDisable" xid="d_decPrice"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="decTotal" label="申报总价" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.decTotal" @keyup.enter.native="countPrice" placeholder="" decimal int-length="15" precision="2" :disabled="showDisable" xid="d_decTotal"></xdo-input>
                    </XdoFormItem>
                  <XdoFormItem prop='destinationCountry' label='最终目的国（地区）' xid='c_head_edit_form_item'>
                    <xdo-select v-model='formItem.destinationCountry' :disabled='showDisable' :asyncOptions='pcodeList'
                                :meta='pcode.country_outdated' :optionLabelRender='pcodeRender'
                                xid='d_destinationCountry'></xdo-select>
                  </XdoFormItem>
                    <XdoFormItem  label="境内目的地/境内货源地" xid="c_head_edit_form_item">
                        <xdo-select :style="{width:160+'px'}" prop="districtCode" v-model="formItem.districtCode" :disabled="showDisable" :asyncOptions="pcodeList" :meta="pcode.area" :optionLabelRender="pcodeRender" xid="d_districtCode"></xdo-select>

                        <xdo-select v-model="formItem.districtPostCode" :style="{width:160+'px'}" prop="districtPostCode" :disabled="showDisable" :asyncOptions="pcodeList" :meta="pcode.post_area" :optionLabelRender="pcodeRender" xid="d_districtPostCode"></xdo-select>
                    </XdoFormItem>
<!--                    <XdoFormItem  label="境内目的地-行政区" xid="c_head_edit_form_item">-->
<!--                        <xdo-select v-model="formItem.districtPostCode" prop="districtPostCode" :disabled="showDisable" :asyncOptions="pcodeList" :meta="pcode.post_area" :optionLabelRender="pcodeRender" xid="d_districtPostCode"></xdo-select>-->
<!--                    </XdoFormItem>-->
                    <XdoFormItem prop="dutyMode" label="征免方式" xid="c_head_edit_form_item">
                        <xdo-select v-model="formItem.dutyMode" :disabled="showDisable" :asyncOptions="pcodeList" :meta="pcode.levymode" :optionLabelRender="pcodeRender" xid="d_dutyMode"></xdo-select>
                    </XdoFormItem>
                    <XdoFormItem prop="exgVersion" label="单耗版本号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.exgVersion" :disabled="showDisable" xid="d_exgVersion"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="factor1" label="第一比例因子" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.factor1" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_factor1"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="factor2" label="第二比例因子" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.factor2" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_factor2"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="factorWt" label="重量比例因子" xid="c_head_edit_form_item">
                        <xdo-input  v-model.trim="formItem.factorWt" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_factorWt"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="gModel" label="规格型号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.gModel"  @blur.native.capture="judgmentCharacter" :disabled="showDisable"  xid="d_gModel"></XdoIInput>
                    </XdoFormItem>

                  <XdoFormItem prop="gName" label="商品名称" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.gName" :disabled="isDisabled" xid="d_gName"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="gNo" label="备案序号" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.gNo" placeholder="" @keyup.native="cleanData" @keyup.enter.native="getGnoMessage" number int-length="9" :disabled="showDisable" xid="d_gNo"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="grossWt" label="毛重" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.grossWt" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_grossWt"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="indbTime" label="入库时间" xid="c_head_edit_form_item">
                        <XdoDatePicker type="date" format="yyyy-MM-dd" placeholder="" :value="formItem.indbTime ? formItem.indbTime.slice(0, 10) : formItem.indbTime" @on-change="formItem.indbTime=($event === '' ? $event : ($event + ' 23:59:59'))" transfer :disabled="showDisable" xid="d_indbTime"></XdoDatePicker>
                    </XdoFormItem>
                    <XdoFormItem prop="netWt" label="净重" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.netWt" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_netWt"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="note" label="备注" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.note" :disabled="showDisable" xid="d_note"></XdoIInput>
                    </XdoFormItem>
                  <XdoFormItem prop='originCountry' label='原产国(地区)' xid='c_head_edit_form_item'>
                    <xdo-select v-model='formItem.originCountry' :disabled='showDisable' :asyncOptions='pcodeList'
                                :meta='pcode.country_outdated' :optionLabelRender='pcodeRender'
                                xid='d_originCountry'></xdo-select>
                  </XdoFormItem>
                    <XdoFormItem prop="passportUsedQty" label="核放单已用数量" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.passportUsedQty" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_passportUsedQty"></xdo-input>
                    </XdoFormItem>

                    <XdoFormItem prop="qty1" label="法定数量" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.qty1" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_qty1"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="qty2" label="法定第二数量" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.qty2" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_qty2"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="rotateGNo" label="流转申报表序号" xid="c_head_edit_form_item">
                      <XdoIInput type="text" v-model="formItem.rotateGNo" :disabled="showDisable" xid="d_rotateGNo"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="seqNo" label="中心统一编号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.seqNo" :disabled="showDisable" xid="d_seqNo"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="serialNo" label="序号" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.serialNo" placeholder="" number int-length="9" disabled xid="d_serialNo"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="unit" label="申报计量单位" xid="c_head_edit_form_item">
                        <xdo-select type="text" v-model="formItem.unit" :disabled="isDisabled" :asyncOptions='pcodeList'
                                   :meta='pcode.unit' :optionLabelRender='pcodeRender' xid="d_unit"></xdo-select>
                    </XdoFormItem>
                    <XdoFormItem prop="unit1" label="法定计量单位" xid="c_head_edit_form_item">
                        <xdo-select type="text" v-model="formItem.unit1" disabled :asyncOptions='pcodeList'
                                   :meta='pcode.unit' :optionLabelRender='pcodeRender' xid="d_unit1"></xdo-select>
                    </XdoFormItem>
                    <XdoFormItem prop="unit2" label="法定第二计量单位" xid="c_head_edit_form_item">
                        <xdo-select type="text" v-model="formItem.unit2" disabled :asyncOptions='pcodeList'
                                   :meta='pcode.unit' :optionLabelRender='pcodeRender' xid="d_unit2"></xdo-select>
                    </XdoFormItem>
                    <XdoFormItem prop="usdPrice" label="美元统计总金额" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.usdPrice" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_usdPrice"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="useType" v-show="false" label="用途" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.useType" :disabled="showDisable" xid="d_useType"></XdoIInput>
                    </XdoFormItem>
                </XdoForm>
            </div>
          <Modal v-model="exgModal" title="查询料号" @on-ok="ok" @on-cancel="cancel" width='1000'>
            <EmsCusExgCurList ref='exgChild' :emsNo='emsNo' @showFormItem='showFormItem'></EmsCusExgCurList>
          </Modal>

          <Modal v-model="imgModal" title="查询料号" @on-ok="ok" @on-cancel="cancel" width='1000'>
            <EmsCusImgCurList ref='imgChild' :emsNo='emsNo' @showImgFormTtem='showImgFormTtem'></EmsCusImgCurList>
          </Modal>
        </XdoCard>
        <div class="xdo-enter-action dc-edit-actions">
            <template v-for="item in buttons">
                <XdoButton v-if="item.needed === true" :type="item.type" :disabled="item.disabled"
                           :loading="item.loading"
                           @click="item.click" :icon="item.icon" :key="item.icon">{{ item.label }}
                </XdoButton>&nbsp;
            </template>
        </div>
    </section>
</template>
<script>
    import { jx_bill_testUri } from '@/api'
    import { editStatus } from '@/view/jx_bill_test-common/constant'
    import { decimalKeypress,decimalKeyup,numberKeypress,numberKeyup} from '@/libs/num'
    import { xwManageListUrl } from '../../../api/jx_bill_test_api_constant'
    import EmsCusExgCurList from '../../exgCurrManage/emsCusExgCur/EmsCusExgCurList'
    import EmsCusImgCurList from '../../imgCurrManage/emsCusImgCur/EmsCusImgCurList'
    import store from '@/store'
    export default {
        name: 'DcBillListXwtEdit',
      components:{
        EmsCusExgCurList,
        EmsCusImgCurList
      },
      props: {
            editConfig: { type: Object, default: () => ({}) },
        },
        data() {
            return {
              emsNo:'',
              //判断当前料号对应的法一或法二和当前商品编码对应pcode中的法一、法二是否相等
              commodityUnit1:'',
              commodityUnit2:'',
              ltemUnit1:'',
              ltemUnit2:'',

              status:'',
              currDisable:false,
              isDisabled:true,
              icon:'',
              showHeadXwtEdit:false,
              num:'',
              exgModal:false,
              imgModal:false,
                showDisable:false,
                formItem: {
                    sid: '',
                    tradeCode: '',
                    emsNo: '',
                    billListNo: '',
                    actlPassQty: '',
                    classifyMark: '',
                    codeTS: '',
                    copGNo: '',
                    curr: '',
                    dataMark: '',
                    decPrice: '',
                    decTotal: '',
                    destinationCountry: '',
                    districtCode: '',
                    districtPostCode: '',
                    dutyMode: '',
                    exgVersion: '',
                    factor1: '',
                    factor2: '',
                    factorWt: '',
                    gModel: '',
                    gName: '',
                    gNo: null,
                    grossWt: '',
                    indbTime: '',
                    netWt: '',
                    note: '',
                    originCountry: '',
                    passportUsedQty: '',
                    qty: '',
                    qty1: '',
                    qty2: '',
                    rotateGNo: '',
                    seqNo: '',
                    serialNo: '',
                    unit: '',
                    unit1: '',
                    unit2: '',
                    usdPrice: '',
                    useType: '',
                },
                ruleValidate: {
                            tradeCode: [
                                    { max: 10, message: '长度不能超过10位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            emsNo: [
                                    { max: 12, message: '长度不能超过12位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            billListNo: [
                                    { max: 18, message: '长度不能超过18位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            actlPassQty: [
                            ],
                            classifyMark: [
                                    { max: 4, message: '长度不能超过4位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            codeTS: [
                                    { max: 10, message: '长度不能超过10位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            copGNo: [
                                    { max: 32, message: '长度不能超过32位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            curr: [
                              { required: true, message: '币制不能为空', trigger: 'blur' },
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            dataMark: [
                                    { max: 128, message: '长度不能超过128位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            decPrice: [
                            ],
                            decTotal: [
                            ],
                            destinationCountry: [
                              { required: true, message: '最终目的国(地区)', trigger: 'blur' },
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            districtCode: [
                                    { max: 5, message: '长度不能超过5位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            districtPostCode: [
                                    { max: 6, message: '长度不能超过6位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            dutyMode: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            exgVersion: [
                                    { max: 8, message: '长度不能超过8位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            factor1: [
                            ],
                            factor2: [
                            ],
                            factorWt: [
                            ],
                            gModel: [
                              { required: true, message: '规格型号不能为空', trigger: 'blur' },
                                    { max: 255, message: '长度不能超过255位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            gName: [
                                    { max: 255, message: '长度不能超过255位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            gNo: [
                            ],
                            grossWt: [
                            ],
                            indbTime: [
                                    { max: null, message: '长度不能超过null位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            netWt: [
                            ],
                            note: [
                                    { max: 256, message: '长度不能超过256位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            originCountry: [
                              { required: true, message: '原产国(地区)不能为空', trigger: 'on-change' },
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            passportUsedQty: [
                            ],
                            qty: [
                              // { required: true, message: '申报数量不能为空', trigger: 'blur' }
                            ],
                            qty1: [
                              // { required: true, message: '法定数量不能为空', trigger: 'blur' }
                            ],
                            qty2: [
                            ],
                            rotateGNo: [
                              { required: false, message: '流转序号表不能为空', trigger: 'blur' },
                                    { max: 64, message: '长度不能超过64位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            seqNo: [
                                    { max: 18, message: '长度不能超过18位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            serialNo: [
                            ],
                            unit: [
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            unit1: [
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            unit2: [
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            usdPrice: [
                            ],
                            useType: [
                                    { max: 2, message: '长度不能超过2位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                },
                buttons: [
                    {
                        code: 'Save',
                        type: 'primary',
                        disabled: false,
                        click: this.handleSave,
                        label: '保存',
                        loading: false,
                        needed: true
                    },
                    {
                        code: 'Cancel',
                        type: 'primary',
                        disabled: false,
                        click: this.handleBack,
                        label: '返回',
                        loading: false,
                        needed: true
                    }
                ]
            }
        },
        mounted: function(){
          this.emsNo=this.editConfig.emsNo
            if (this.editConfig && this.editConfig.editStatus === editStatus.ADD) {
                this.resetFormData()
                this.formItem.headId = this.editConfig.headId
                this.showDisable = false
                this.buttons.filter(item => item.code === "Save")[0].needed = true
              //默认清单流水号
                this.formItem.billListNo=this.editConfig.billListNo
                //账册编号-EMS_NO：默认当前手账册编号
                this.formItem.emsNo=this.editConfig.emsNo
              //当表头监管方式是以下数据时商品编码、商品名称、申报计量单位等信息可以修改
              if (
                this.editConfig.tradeMode=='0844' || this.editConfig.tradeMode=='0845' ||
                this.editConfig.tradeMode=='5200' || this.editConfig.tradeMode=='0400' ||
                this.editConfig.tradeMode=='0864' || this.editConfig.tradeMode=='0865'){
                this.isDisabled=false
              }else {
                this.isDisabled=true
              }
              console.log(this.editConfig.rotateApplyNo)
              //表头“申请表编号”填写时此栏位非空
              if (this.editConfig.rotateApplyNo=='' || this.editConfig.rotateApplyNo==null){
                this.ruleValidate.rotateGNo[0].required=false
              } else {
                this.ruleValidate.rotateGNo[0].required=true
              }
              //动态显示刷新图标
              if (this.editConfig.declareType=='1'){
                this.icon='ios-refresh-circle-outline'
              }
            } else if (this.editConfig && this.editConfig.editStatus === editStatus.EDIT) {
                this.formItem = { ...this.editConfig.editData }
                this.formItem.headId = this.editConfig.headId
                this.showDisable = false
                this.buttons.filter(item => item.code === "Save")[0].needed = true
            } else if (this.editConfig && this.editConfig.editStatus === editStatus.SHOW) {
                this.formItem = { ...this.editConfig.editData }
                this.formItem.headId = this.editConfig.headId
                this.showDisable = true
                this.buttons.filter(item => item.code === "Save")[0].needed = false
            } else {
                this.$Message.error('缺失编辑信息!')
            }
            //当表头监管方式是以下数据时币制默认142 人民币 不可修改
          if (this.editConfig.tradeMode==='0644' || this.editConfig.tradeMode==='0245' || this.editConfig.tradeMode==='0844' || this.editConfig.tradeMode==='0845'){
            this.formItem.curr="142"
            this.currDisable=true
            //设置默认征免方式
            this.formItem.dutyMode='1'
          }else {
            this.formItem.dutyMode='3'
          }
        },
        methods: {
          //计算总价和单价
          countPrice(){
            if (this.formItem.qty==null || this.formItem.qty==''){
              alert("申报数量不能为空")
            } else if ((this.formItem.decPrice==''||this.formItem.decPrice==null)&&(this.formItem.decTotal==''||this.formItem.decTotal==null)){
              alert("单价、总价不能同时为空")
            }else if (this.formItem.decPrice!='' && this.formItem.decPrice!=null){//单价非空计算总价
              let num=this.formItem.decPrice*this.formItem.qty
                  num=num.toFixed(2)
              this.formItem.decTotal=num
            } else if (this.formItem.decPrice=='' || this.formItem.decPrice==null){//单价为空计算单价
              let num=this.formItem.decTotal/this.formItem.qty
                  num=num.toFixed(5)
              this.formItem.decPrice=num
            }else if (this.formItem.decTotal!='' && this.formItem.decTotal!=null){
              let num=this.formItem.decTotal/this.formItem.qty
                  num=num.toFixed(5)
              this.formItem.decPrice=num
            }else if (this.formItem.decTotal=='' || this.formItem.decTotal==null){
              let num=this.formItem.decPrice*this.formItem.qty
              num=num.toFixed(5)
              this.formItem.decTotal=num
            }
          },

          //判断文本框是否有违规字符
          judgmentCharacter(){
            let regEn = /[`!@#$%^&*_+<>?"{}'[\]]/im,

              regCn = /[·！#￥——“”‘、|《。》？【】[\]]/im;

            if(regEn.test(this.formItem.gModel) || regCn.test(this.formItem.gModel)) {
              alert("字符违规")
            }

          },
          //根据商品编码从pcode获取法定单位、法定第二单位
          getUnitByCodeTs(){
            if(this.formItem.codeTS=='' || this.formItem.codeTS==null){
              alert("商品编码为空")
            } else {
              this.$http.get('/api/pcode?type=COMPLEX&code='+this.formItem.codeTS).then(res => {
                this.formItem.unit1=res.data.data[0].UNIT_1;
                this.formItem.unit2=res.data.data[0].UNIT_2;

                this.commodityUnit1=res.data.data[0].UNIT_1;
                this.commodityUnit2=res.data.data[0].UNIT_2;
              }, () => {});
            }
          },
          //双击传入料号
          showImgFormTtem(row){
            this.formItem.gNo=row.gNo
            this.formItem.codeTS=row.codeTS
            this.formItem.gName=row.gName
            this.formItem.gModel=row.gModel
            this.formItem.unit=row.unit
            this.formItem.unit1=row.unit1
            this.formItem.unit2=row.unit2
            this.formItem.copGNo=row.copGNo
            this.imgModal=false
          },
          //双击传入料号
          showFormItem(row){
            this.formItem.gNo=row.gNo
            this.formItem.codeTS=row.codeTS
            this.formItem.gName=row.gName
            this.formItem.gModel=row.gModel
            this.formItem.unit=row.unit
            this.formItem.unit1=row.unit1
            this.formItem.unit2=row.unit2
            this.formItem.copGNo=row.copGNo
            this.exgModal=false
          },
          //备案序号修改时清空之前备案序号对应料号的所有相关数据信息
          cleanData(){
            this.formItem.copGNo=''
            this.formItem.codeTS=''
            this.formItem.gName=''
            this.formItem.gModel=''
            this.formItem.unit=''
            this.formItem.unit1=''
            this.formItem.unit2=''
          },
          getCurList(){
            if (this.editConfig.gMark=='E'){
              this.exgModal=true
              this.$refs.exgChild.getList();
            }else {
              this.imgModal=true
              this.$refs.imgChild.getList();
            }
          },
          //333333333
          getGnoMessage(){
            if (this.editConfig.gMark=='E'){
              this.$http.post(jx_bill_testUri.xwManageListUrl.dcBillListXwt.getExgCurrByGNo,{gNo:this.formItem.gNo,emsNo:this.editConfig.emsNo}).then(res => {
                if (res.data.data!=null) {
                  console.log(res.data)
                  this.formItem.copGNo=res.data.data.copGNo
                  this.formItem.codeTS=res.data.data.codeTS
                  this.formItem.gName=res.data.data.gname
                  this.formItem.gModel=res.data.data.gmodel
                  this.formItem.unit=res.data.data.unit
                  this.formItem.unit1=res.data.data.unit1
                  this.formItem.unit2=res.data.data.unit2
                }else {
                  alert("该商品序号未备案!")
                }
              }, () => {});
            }else {
              this.$http.post(jx_bill_testUri.xwManageListUrl.dcBillListXwt.getImgCurrByGNo,{gNo:this.formItem.gNo,emsNo:this.editConfig.emsNo}).then(res => {
                if (res.data.data!=null) {
                  this.formItem.copGNo=res.data.data.copGNo
                  this.formItem.codeTS=res.data.data.codeTS
                  this.formItem.gName=res.data.data.gname
                  this.formItem.gModel=res.data.data.gmodel
                  this.formItem.unit=res.data.data.unit
                  this.formItem.unit1=res.data.data.unit1
                  this.formItem.unit2=res.data.data.unit2
                }else {
                  alert("该商品序号未备案!")
                }
              }, () => {});
            }
          },
          getCopGNoMessage(){
            //回车自动根据商品料号、清单表头的料件成品标志，带出手(账)册料件/成品的备案序号、商品编码、商品名称、规格型号、申报计量单位、法定计量单位、法定第二单位
            if (this.editConfig.gMark=='E'){
              this.$http.post(jx_bill_testUri.xwManageListUrl.dcBillListXwt.getExgCurr,{copGNo:this.formItem.copGNo,emsNo:this.editConfig.emsNo}).then(res => {
                if (res.data.data!=null) {
                  this.formItem.gNo=res.data.data.gno
                  this.formItem.codeTS=res.data.data.codeTS
                  this.formItem.gName=res.data.data.gname
                  this.formItem.gModel=res.data.data.gmodel
                  this.formItem.unit=res.data.data.unit
                  this.formItem.unit1=res.data.data.unit1
                  this.formItem.unit2=res.data.data.unit2
                  this.ltemUnit1=res.data.data.unit1;
                  this.ltemUnit2=res.data.data.unit2;
                }else {
                  alert("该商品料号未备案!")
                }
              }, () => {});
            }else {
              this.$http.post(jx_bill_testUri.xwManageListUrl.dcBillListXwt.getCopGNoIsNull,{copGNo:this.formItem.copGNo,emsNo:this.editConfig.emsNo}).then(res => {
                if (res.data.data!=null) {
                  this.formItem.gNo=res.data.data.gno
                  this.formItem.codeTS=res.data.data.codeTS
                  this.formItem.gName=res.data.data.gname
                  this.formItem.gModel=res.data.data.gmodel
                  this.formItem.unit=res.data.data.unit
                  this.formItem.unit1=res.data.data.unit1
                  this.formItem.unit2=res.data.data.unit2
                  this.ltemUnit1=res.data.data.unit1;
                  this.ltemUnit2=res.data.data.unit2;
                }else {
                  alert("该商品料号未备案!")
                }
              }, () => {});
            }
          },
            resetFormData() {
                this.$refs['formItem'].resetFields()
            },
          abc(){
            this.$http.get('/api/pcode?type=COMPLEX&code='+this.formItem.codeTS).then(res => {
              if (res.data.success){
                debugger;
                this.commodityUnit1=res.data.data[0].UNIT_1;
                this.commodityUnit2=res.data.data[0].UNIT_2;
                if (this.formItem.unit1!=this.commodityUnit1){
                  alert("当前料号对应的法一和当前商品编码对应pcode中的法一不一致");
                  return;
                }
                if (this.formItem.unit2!=this.commodityUnit2){
                  alert("当前料号对应的法二和当前商品编码对应pcode中的法二不一致");
                  return;
                }
              }
            }, () => {});
          },
            handleSave() {
               this.abc();

              console.log(this.commodityUnit1)
              console.log(this.formItem.unit1)

              //若申报计量单位与法定第一单位一致，则使用此值填充法定第一数量；若申报计量单位与法定第二单位一致，则使用此值填充法定第二数量
                if (this.formItem.unit==this.formItem.unit1){
                  this.formItem.qty1=this.formItem.qty
                }else {
                  let num=this.formItem.qty*this.formItem.factor1
                  num=num.toFixed(5)
                  this.formItem.qty1=num
                }
                if (this.formItem.unit==this.formItem.unit2){
                  this.formItem.qty2=this.formItem.qty
                }
            // this.status=this.editConfig.status;
            //   //检验当前状态下保存按钮是否能用
            //   if ((this.status=='B1' || this.status=='C1' || this.status=='0' ||
            //     this.status=='1' || this.status=='2' || this.status=='DL' ||
            //     this.status=='4' || this.status=='5' || this.status=='Y')){
            //     alert("当前状态不可保存!")
            //     return;
            //   }
            //   if (((this.status=='D1' && this.editConfig.declareType!='1')||
            //     (this.status=='3'&&this.editConfig.declareType!='1')||
            //     (this.status=='Z'&&this.editConfig.declareType!='1'))){
            //     alert("当前状态不可保存!")
            //     return;
            //   }
              if ((this.formItem.gNo==''||this.formItem.gNo==null) && (this.formItem.copGNo=='' || this.formItem.copGNo==null)){
                alert("商品料号和备案序号不可同时为空")
              }else {
                this.$refs['formItem'].validate().then(isValid => {

                  //若“申报计量单位”是千克，净重取“申报数量”的值
                  if (this.formItem.unit=='035'){
                      this.formItem.netWt=this.formItem.qty
                          //若不同、且重量比例因子不为空，则取申报数量*重量比例因子的值，四舍五入成5位小数
                  }else if (this.formItem.unit!='035' && this.formItem.factorWt!=''){
                      let num=this.formItem.qty*this.formItem.factorWt
                    num=num.toFixed(5)
                    this.formItem.netWt=num
                  }
                  if (this.formItem.qty==null || this.formItem.qty==''){
                    alert("申报数量不能为空")
                    return;
                  } else if ((this.formItem.decPrice==''||this.formItem.decPrice==null)&&(this.formItem.decTotal==''||this.formItem.decTotal==null)){
                    alert("单价、总价不能同时为空")
                    return;
                  }
                  //若“申报计量单位”与“法定计量单位”相同，将“第一比例因子”自动填充为1
                  if (this.formItem.unit==this.formItem.unit1){
                    this.formItem.factor1='1'
                  }
                  //若“申报计量单位”与“法定第二计量单位”相同，将“第二比例因子”自动填充为1
                  if (this.formItem.unit==this.formItem.unit2){
                    this.formItem.factor2='1'
                  }
                  //若“申报计量单位”是千克，将“重量比例因子”自动填充为1
                  if (this.formItem.unit=='035'){
                    this.formItem.factorWt='1'
                  }
                  //当前数据的申报计量单位与法定计量单位相同时而申报数量与法定数量是否相同
                  if (this.formItem.unit==this.formItem.unit1 && this.formItem.qty!=this.formItem.qty1){
                    alert("申报计量单位和法定计量单位一致，但申报数量和法定数量不一致");
                    return;
                  }
                  //判断输入框是否为空
                  if (this.formItem.copGNo==''||this.formItem.copGNo==null){
                    alert('商品料号不能为空');
                    return;
                  }
                  if (this.formItem.gNo==''||this.formItem.gNo==null){
                    alert('备案序号不能为空');
                    return;
                  }
                  if (this.formItem.gModel==''||this.formItem.gModel==null){
                    alert('规格型号不能为空');
                    return;
                  }
                  if (this.formItem.originCountry==''||this.formItem.originCountry==null){
                    alert('原产国(地区)不能为空');
                    return;
                  }
                  if (this.formItem.destinationCountry==''||this.formItem.destinationCountry==null){
                    alert('最终目的国(地区)不能为空');
                    return;
                  }
                  if (this.formItem.qty==''||this.formItem.qty==null){
                    alert('申报数量不能为空');
                    return;
                  }
                  if (this.formItem.decPrice==''||this.formItem.decPrice==null){
                    alert('申报单价不能为空');
                    return;
                  }
                  if (this.formItem.decTotal==''||this.formItem.decTotal==null){
                    alert('申报总价不能为空');
                    return;
                  }
                  if (this.formItem.qty1==''||this.formItem.qty1==null){
                    alert('法定数量不能为空');
                    return;
                  }
                  if (this.formItem.dutyMode==''||this.formItem.dutyMode==null){
                    alert('征免方式不能为空');
                    return;
                  }

                  //保存时校验申报总价/申报数量=企业申报单价的公式是否符合
                  let n=this.formItem.decTotal/this.formItem.qty
                  n=n.toFixed(5)
                  if (this.formItem.decPrice!=n){
                    //确认对话框,点击确认继续保存
                    this.$Modal.confirm({
                      title: '警告',
                      content: '<p>总价/数量与单价不等！</p><p>继续保存点确认</p>',
                      onOk: () => {
                        if (isValid) {
                          let http = ''
                          this.buttons.filter(item => item.code === "Save")[0].loading = true
                          const sid = this.formItem.sid
                          if (sid) {
                            http = this.$http.put(`${jx_bill_testUri.xwManageListUrl.dcBillListXwt.update}/${sid}`, this.formItem, {noIntercept: true})
                          } else {
                            http = this.$http.post(jx_bill_testUri.xwManageListUrl.dcBillListXwt.insert, this.formItem, {noIntercept: true})
                          }
                          http.then(res => {
                            if (res.data.success) {
                              this.$Message.success(res.data.message)
                              this.handleBack()
                            } else {
                              this.$Message.error(res.data.message)
                            }
                          }, () => {}).finally(() => {
                            this.buttons.filter(item => item.code === "Save")[0].loading = false
                          })
                        }
                      },
                      onCancel: () => {
                        this.$Message.info('点击了取消');
                      }
                    });
                    return;
                  }else {
                    if (isValid) {
                      let http = ''
                      this.buttons.filter(item => item.code === "Save")[0].loading = true
                      const sid = this.formItem.sid
                      if (sid) {
                        http = this.$http.put(`${jx_bill_testUri.xwManageListUrl.dcBillListXwt.update}/${sid}`, this.formItem, {noIntercept: true})
                      } else {
                        http = this.$http.post(jx_bill_testUri.xwManageListUrl.dcBillListXwt.insert, this.formItem, {noIntercept: true})
                      }
                      http.then(res => {
                        if (res.data.success) {
                          this.$Message.success(res.data.message)
                          this.handleBack()
                        } else {
                          this.$Message.error(res.data.message)
                        }
                      }, () => {}).finally(() => {
                        this.buttons.filter(item => item.code === "Save")[0].loading = false
                      })
                    }
                  }

                })
              }

            },
            handleBack() {
                this.$emit('onEditBack', true)
            },
            decimalKeypress,decimalKeyup,numberKeypress,numberKeyup
        }
    }
</script>
<style lang="less" scoped>
</style>
